/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package marsaMaroc.controllers;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import marsaMaroc.dao.ClientDAO;
import marsaMaroc.dao.FactureDAO;
import marsaMaroc.dao.ReclamationDAO;
import marsaMaroc.model.Client;
import marsaMaroc.model.Facture;
import marsaMaroc.model.Reclamation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author Administrateur
 */
@Controller
public class FactureController {
    
    FactureDAO factureDAO = new FactureDAO();
    
    @RequestMapping(value = "/addFacture.htm", method = RequestMethod.POST)
    protected ModelAndView add(
            @RequestParam("type") String type,
            @RequestParam("motif") String motif,
            @RequestParam("date") Date date,
            @RequestParam("statut") String statut
    ) throws Exception {
        
        Facture rec = new Facture();
//        rec.setType(type);
//        rec.setMotif(motif);
//        rec.setDateCreation(date);
//        rec.setStatut(statut);
//        
//        reclamationtDAO.add(rec);        
        return new ModelAndView("index");
    }

    
    @RequestMapping(value = "/deleteFacture.htm", method = RequestMethod.POST)
    protected ModelAndView delete(
            @RequestParam("id") Long id
    ) throws Exception {
        
       // Reclamation c = (Reclamation) reclamationtDAO.get(id);        
      //  reclamationtDAO.delete(c);
        return new ModelAndView("index");
    }
    
     @RequestMapping(value = "/newFacture.htm", method = RequestMethod.GET)
    protected ModelAndView newF() throws Exception {
        
        List<Client> clients = new ClientDAO().getAll();
        return new ModelAndView("Factur_crud/add","clients",clients);
    }
    
    
    @RequestMapping(value = "/listFacture.htm", method = RequestMethod.GET)
    protected ModelAndView getAll(HttpServletRequest request) throws Exception {
        
        List<Facture> listF =  factureDAO.getAll();
        request.getSession().setAttribute("listeF", listF);
        return new ModelAndView("client_crud/list_fac");
    }
    
}
